/*
 * @描述: 
 * @创建者: kilomChou
 * @Date: 2021-04-24 12:43:16
 * @最后编辑: kilomChou
 * @LastEditTime: 2021-04-24 13:55:02
 */

/** 
 * 获取控制台参数
 * @param prefix 参数前缀
 * 例子：
 * //拿到控制台以"-"为前缀的参数
 * let args = getArgs("-");
 */
export function getArgs(prefix: string = "-") {
    let args: { [argName: string]: string } = {}
    let curArg = "";
    process.argv.forEach(arg => {
        if (curArg) {
            args[curArg] = arg;
            curArg = "";
        } else {
            let match = arg.match(new RegExp(`^${prefix}`));
            if (match) {
                curArg = arg.replace(match[0], "");
            }
        }
    });
    return args;
}